﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.ProductionManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.ProductionManagement.ProductionInboundVMs
{
    public partial class ProductionInboundListVM : BasePagedListVM<ProductionInbound_View, ProductionInboundSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ProductionInbound_View>> InitGridHeader()
        {
            return new List<GridColumn<ProductionInbound_View>>{
                
                this.MakeGridHeader(x => x.ProductionInbound_LineId).SetTitle(@Localizer["Page.产线"].Value),
                this.MakeGridHeader(x => x.ProductionInbound_LineCode).SetTitle(@Localizer["Page.产线编码"].Value),
                this.MakeGridHeader(x => x.ProductionInbound_OpId).SetTitle(@Localizer["Page.工位"].Value),
                this.MakeGridHeader(x => x.ProductionInbound_OpCode).SetTitle(@Localizer["Page.工位号"].Value),
                this.MakeGridHeader(x => x.ProductionInbound_ProductId).SetTitle(@Localizer["Page.产品"].Value),
                this.MakeGridHeader(x => x.ProductionInbound_ProductCode).SetTitle(@Localizer["Page.产品编号"].Value),
                this.MakeGridHeader(x => x.ProductionInbound_Sn).SetTitle(@Localizer["Page.追溯码"].Value),
                this.MakeGridHeader(x => x.ProductionInbound_Wo).SetTitle(@Localizer["Page.工单"].Value),
                this.MakeGridHeader(x => x.ProductionInbound_Rfid).SetTitle(@Localizer["Page.Rfid"].Value),
                this.MakeGridHeader(x => x.ProductionInbound_InboundTime).SetTitle(@Localizer["Page.进站时间"].Value),
                this.MakeGridHeader(x => x.ProductionInbound_InboundStatus).SetTitle(@Localizer["Page.进站状态"].Value),
                this.MakeGridHeader(x => x.ProductionInbound_Ver).SetTitle(@Localizer["Page.版本"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ProductionInbound_View> GetSearchQuery()
        {
            var query = DC.Set<ProductionInbound>()
                
                .CheckEqual(Searcher.LineId, x=>x.LineId)
                .CheckContain(Searcher.LineCode, x=>x.LineCode)
                .CheckEqual(Searcher.OpId, x=>x.OpId)
                .CheckContain(Searcher.OpCode, x=>x.OpCode)
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductCode, x=>x.ProductCode)
                .CheckContain(Searcher.Sn, x=>x.Sn)
                .CheckContain(Searcher.Wo, x=>x.Wo)
                .CheckContain(Searcher.Rfid, x=>x.Rfid)
                .CheckBetween(Searcher.InboundTime?.GetStartTime(), Searcher.InboundTime?.GetEndTime(), x => x.InboundTime, includeMax: false)
                .CheckEqual(Searcher.InboundStatus, x=>x.InboundStatus)
                .CheckEqual(Searcher.Ver, x=>x.Ver)
                .Select(x => new ProductionInbound_View
                {
				    ID = x.ID,
                    
                    ProductionInbound_LineId = x.LineId,
                    ProductionInbound_LineCode = x.LineCode,
                    ProductionInbound_OpId = x.OpId,
                    ProductionInbound_OpCode = x.OpCode,
                    ProductionInbound_ProductId = x.ProductId,
                    ProductionInbound_ProductCode = x.ProductCode,
                    ProductionInbound_Sn = x.Sn,
                    ProductionInbound_Wo = x.Wo,
                    ProductionInbound_Rfid = x.Rfid,
                    ProductionInbound_InboundTime = x.InboundTime,
                    ProductionInbound_InboundStatus = x.InboundStatus,
                    ProductionInbound_Ver = x.Ver,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ProductionInbound_View: ProductionInbound
    {
        
        public long? ProductionInbound_LineId { get; set; }
        public string ProductionInbound_LineCode { get; set; }
        public long? ProductionInbound_OpId { get; set; }
        public string ProductionInbound_OpCode { get; set; }
        public long? ProductionInbound_ProductId { get; set; }
        public string ProductionInbound_ProductCode { get; set; }
        public string ProductionInbound_Sn { get; set; }
        public string ProductionInbound_Wo { get; set; }
        public string ProductionInbound_Rfid { get; set; }
        public DateTime? ProductionInbound_InboundTime { get; set; }
        public SnStatusEnum? ProductionInbound_InboundStatus { get; set; }
        public long? ProductionInbound_Ver { get; set; }

    }

}